package br.com.gbvbahia.mybooks.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;
import br.com.gbvbahia.mybooks.R;
import br.com.gbvbahia.mybooks.modelos.LivroVO;

public class LivroInfoPesquisaFragment extends FragmentMae {

	private TextView tNome;
	private TextView tNota;
	private TextView tDescricao;
	private TextView tAvaliacao;
	private LinearLayout l1;
	private LinearLayout l2;
	private LinearLayout l3;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.frag_pesq_info, null);
		view.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
				LayoutParams.MATCH_PARENT));
		tNome = (TextView) view.findViewById(R.id.tNomeLivro);
		tNota = (TextView) view.findViewById(R.id.textNotaValue);
		tDescricao = (TextView) view.findViewById(R.id.textDescValue);
		tAvaliacao = (TextView) view.findViewById(R.id.textAvaliacaoValue);
		l1 = (LinearLayout) view.findViewById(R.id.layInfoPesq1);
		l2 = (LinearLayout) view.findViewById(R.id.layInfoPesq2);
		l3 = (LinearLayout) view.findViewById(R.id.layInfoPesq3);
		esconder();
		return view;
	}

	/**
	 * 
	 */
	private void esconder() {
		tNome.setVisibility(TextView.INVISIBLE);
		tNota.setVisibility(TextView.INVISIBLE);
		tDescricao.setVisibility(TextView.INVISIBLE);
		tAvaliacao.setVisibility(TextView.INVISIBLE);
		l1.setVisibility(TextView.INVISIBLE);
		l2.setVisibility(TextView.INVISIBLE);
		l3.setVisibility(TextView.INVISIBLE);
	}

	/**
	 * 
	 */
	private void ver() {
		tNome.setVisibility(TextView.VISIBLE);
		tNota.setVisibility(TextView.VISIBLE);
		tDescricao.setVisibility(TextView.VISIBLE);
		tAvaliacao.setVisibility(TextView.VISIBLE);
		l1.setVisibility(TextView.VISIBLE);
		l2.setVisibility(TextView.VISIBLE);
		l3.setVisibility(TextView.VISIBLE);
	}

	public void setLivro(LivroVO vo) {
		if (vo == null) {
			tNome.setText("");
			tNota.setText("");
			tDescricao.setText("");
			tAvaliacao.setText("");
			esconder();
		} else {
			tNome.setText(vo.getNomeLivro());
			if (vo.getNota() >= 0) {
				tNota.setText(Integer.toString(vo.getNota()));
			} else {
				tNota.setText("");
			}
			tDescricao.setText(vo.getDescricao());
			tAvaliacao.setText(vo.getAvaliacao());
			ver();
		}
	}
}
